<%@ page import="java.util.ArrayList" %>
<%@ page import="vo.Teacher" %>
<%@ page import="dao.TuitionRecordDao" %>
<%@ page import="vo.TuitionRecord" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" href="../resources/css/jquery-ui-1.10.4.custom.min.css">
    <script src="../resources/js/jquery-1.10.2.js"></script>
    <script src="../resources/js/jquery-ui-1.10.4.custom.min.js"></script>
    <title>main</title>
    <link href="../resources/css/default.css" rel="stylesheet"/>
</head>
<body>
<%
    Teacher teacher = (Teacher) session.getAttribute("info");
    int sumIndex = (int) session.getAttribute("sumIndex");
%>
<div id="page" class="container">
    <div id="header">
        <div id="logo">
            <img src="../userImg/<%=teacher.getId()%>.jpeg"/>
            <h1><%=teacher.getId()%></h1>
        </div>
        <div id="menu">
            <ul>
                <li><a href="personal.jsp">个人信息</a></li>
                <li><a href="../one_page_student">学生管理</a></li>
                <li><a href="../one_page_course">课程管理</a></li>
                <li><a href="../one_page_attendance?teacher_id=<%=teacher.getId()%>">出勤管理</a></li>
                <li><a href="../one_page_score">成绩管理</a></li>
                <li class="current_page_item"><a href="../one_page_tuition_records">学费管理</a></li>
                <li><a onclick="return confirm('确认退出?');" href="../exit">退出登录</a></li>
            </ul>
        </div>
    </div>
    <div id="main">
        <div class="top">
            <h2>学生费用管理</h2>
            <hr/>
            <button class="btn-add">添加缴费信息</button>
        </div>
        <form method="post" action="../update_tuition_record" style="height: 525px; margin-top: 80px">
            <input type="button" class="btn-excel" style="float: left;margin-top: 8px" onclick="location.href='tuition_record_excel.jsp';" value="导出EXCEL">
            <input type="submit" class="btn-add" style="float: right;margin-bottom: 30px" value="修改">
            <div class="table" style="margin-top: 20px; height: 525px">
                <table id="table" width="800" frame="box" align="center">
                    <tr>
                        <th height="35">学号</th>
                        <th>姓名</th>
                        <th width="200px">缴费日期</th>
                        <th>缴费金额</th>
                    </tr>
                    <%
                        try {
                            TuitionRecordDao tuitionRecordDao = new TuitionRecordDao();
                            ArrayList<TuitionRecord> list;
                            if(session.getAttribute("onePageTuitionRecords") != null) {
                                list = (ArrayList<TuitionRecord>) session.getAttribute("onePageTuitionRecords");
                            }else {
                                list = tuitionRecordDao.findAll();
                            }
                            for (TuitionRecord t : list) {
                    %>
                    <tr>
                        <td height="35"><%=t.getStudentId()%></td>
                        <td><input value="<%=t.getStudentName()%>" name="name" class="table-input" style="width: 100px"></td>
                        <td width="200px"><input style="width: 200px" value="<%=t.getPaymentDate()%>" name="paymentDate" class="table-input" width="60"></td>
                        <td><input value="<%=t.getAmount()%>" name="amount" class="table-input" style="width: 100px"></td>
                        <td><a class="btn-delete"
                               onclick="return confirm('确定要删除吗?');"
                               href=<%="'../delete_tuition_record?id=" + t.getRecordId() + "'"%>>删除</a></td>
                    </tr>
                    <%
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    %>
                </table>

            </div>
        </form>

        <%
            if (sumIndex > 1){
        %>
        <div id="index">
            <a href="../one_page_tuition_records?index=1">首页</a>
            <%
                for (int i = 1; i <= sumIndex; i++) {
            %>
            <a href="../one_page_tuition_records?index=<%=i%>">第<%=i%>页</a>
            <%
                }
            %>
            <a href="../one_page_tuition_records?index=<%=sumIndex%>">尾页</a>
        </div>
        <%
            }
        %>
    </div>
</div>

<div id="add-dialog" title="添加缴费信息">
    <form id="add-form" method="post">
        学生学号:<input name="student_id" type="text"><br>
        学生姓名:<input name="student_name" type="text"><br>
        缴费日期:<input name="payment_date" type="date"><br>
        缴费金额:<input name="amount" type="text"><br>
        <hr>
        <input style="float: right" type="submit" value="取消" onclick="function x() {
          $('#add-dialog').dialog('close');
        }">
        <input style="float: right; margin-right: 25px" type="submit" value="确定"
               onclick="this.form.action='../add_tuition_record'">
    </form>
</div>

<style>
    .ui-dialog-titlebar-close {
        display: none
    }
</style>

<script>
    $('#add-dialog').dialog({
        width: 310,
        autoOpen: false,
        draggable: false,
        modal: true,
        resizable: false
    });
    $('.btn-add').click(function () {
        $('#add-dialog').dialog('open');
    });
</script>
</body>
</html>
